<template>
    <el-row>
        <el-form :inline="true"
            :model="productSearchObj"
            class="search_prod tl">
            <el-form-item label="">
                <el-input size="small"
                    clearable
                    v-model="productSearchObj.username"
                    placeholder="商户用户名"></el-input>
            </el-form-item>

            <el-form-item label="">
                <el-input size="small"
                    clearable
                    v-model="productSearchObj.title"
                    placeholder="商品名称"></el-input>
            </el-form-item>
            <el-form-item label="">
                <el-select v-model="productSearchObj.is_check"
                    clearable
                    size="small"
                    placeholder="处理状态">
                    <el-option v-for="item in checkList"
                        size="small"
                        :key="item.id"
                        :label="item.title"
                        :value="item.id">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label=""
                class="time_width">
                <el-date-picker v-model="createTime"
                    type="datetimerange"
                    size="small"
                    align="right"
                    unlink-panels
                    value-format="timestamp"
                    range-separator="-"
                    clearable
                    start-placeholder="开始时间"
                    end-placeholder="结束时间"
                    :picker-options="pickerOptions2">
                </el-date-picker>
            </el-form-item>
            <el-form-item label="">
                <el-row class="tl">
                    <el-col :span="24">
                        <el-button :loading='$store.state.isLoading'
                            size="small"
                            class="top_weiy"
                            type="primary"
                            @click="onSubmit">查询</el-button>
                        <el-button :loading='$store.state.isLoading'
                            size="small"
                            class="top_weiy"
                            type="primary"
                            @click="delSubmit">一键清除</el-button>
                    </el-col>
                </el-row>
            </el-form-item>
        </el-form>
    </el-row>
</template>
<script>
export default {
    data () {
        return {
            pickerOptions2: {
                disabledDate (time) {
                    return time.getTime() > Date.now();
                },
                shortcuts: [
                    {
                        text: "最近一周",
                        onClick (picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                            picker.$emit("pick", [start, end]);
                        }
                    },
                    {
                        text: "最近一个月",
                        onClick (picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                            picker.$emit("pick", [start, end]);
                        }
                    },
                    {
                        text: "最近三个月",
                        onClick (picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                            picker.$emit("pick", [start, end]);
                        }
                    }
                ]
            },
            createTime: [],
            productSearchObj: {
                username: "",
                title: "",
                is_check: "",
                created_time_begin: "",
                created_time_end: ""
            },
            checkList: [{ id: "0", title: "未处理" }, { id: "1", title: "已通过" }, { id: "2", title: "未通过" }]
        };
    },
    methods: {
        delSubmit () {
            this.productSearchObj = {
                username: "",
                title: "",
                is_check: "",
                created_time_begin: "",
                created_time_end: ""
            };
            this.$emit("sendSearch", this.productSearchObj);
        },
        onSubmit () {
            this.$emit("sendSearch", this.productSearchObj);
        }
    },
    watch: {
        createTime (val) {
            if (val != null) {
                this.productSearchObj.created_time_begin = this.$fnc.phptime(val[0]);
                this.productSearchObj.created_time_end = this.$fnc.phptime(val[1]);
            } else {
                this.productSearchObj.created_time_begin = "";
                this.productSearchObj.created_time_end = "";
            }
        }
    }
};
</script>
